package leetcodecompetition.D344;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class T6417 {
    class FrequencyTracker {
        Map<Integer, Integer> map;

        public FrequencyTracker() {
            map = new HashMap<>();
        }

        public void add(int number) {
            map.put(number, map.containsKey(number) ? map.get(number) + 1 : 1);
        }

        public void deleteOne(int number) {
            map.remove(number);
        }

        public boolean hasFrequency(int frequency) {
            for (int key : map.keySet()) {
                if (map.get(key) == frequency)
                    return true;
            }
            return false;
        }
    }

    class FrequencyTracker1 {
        int[] arr;
        int[] cnt;

        public FrequencyTracker1() {
            arr = new int[100000];
            cnt = new int[100000];
        }

        public void add(int number) {
            cnt[arr[number]]--;
            arr[number]++;
            cnt[arr[number]]++;
        }

        public void deleteOne(int number) {
            if (arr[number]>0){
                cnt[arr[number]]--;
                arr[number]--;
                cnt[arr[number]]++;
            }
        }

        public boolean hasFrequency(int frequency) {
            return cnt[frequency] != 0;
        }
    }
}
